package cn.gdcp.animationset;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private Button btnStart;
    private ImageView ivYaya;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnStart = findViewById(R.id.btnStart);
        ivYaya = findViewById(R.id.iv_yaya);

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //startRotateWithJava();
                startRotateWithXML();
                startAnimationSetWithJava();
                startAnimationSetWithXml();

            }
        });
    }

    private void startAnimationSetWithXml() {
        AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(MainActivity.this,R.anim.animation_set);
        ivYaya.startAnimation(animationSet);
    }

    private void startAnimationSetWithJava() {
        AnimationSet animationSet = new AnimationSet(true);
        TranslateAnimation translateAnimation = new TranslateAnimation(0,400,0,600);
        RotateAnimation rotateAnimation = new RotateAnimation(0,360,180,180);
        ScaleAnimation scaleAnimation = new ScaleAnimation(1,3,1,3,180,180);
        animationSet.addAnimation(translateAnimation);
        animationSet.addAnimation(rotateAnimation);
        animationSet.addAnimation(scaleAnimation);
        animationSet.setDuration(3000);
        animationSet.setRepeatCount(5);
        animationSet.setRepeatMode(Animation.REVERSE);
        ivYaya.startAnimation(animationSet);
    }

    private void startRotateWithXML() {
        RotateAnimation rotateAnimation = (RotateAnimation)AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate);
        ivYaya.startAnimation(rotateAnimation);
    }

    private void startRotateWithJava() {
        RotateAnimation rotateAnimation = new RotateAnimation(0,360,180,180);
        rotateAnimation.setDuration(3000);
        rotateAnimation.setFillAfter(true);
        ivYaya.startAnimation(rotateAnimation);
    }
}












































